#!/bin/bash
# STDIO mode startup script for Codebase RAG MCP Server
set -e

# Change to script directory
cd "$(dirname "$0")"

# Check if node_modules exists, if not install dependencies
if [ ! -d "node_modules" ]; then
    echo "Installing dependencies..." >&2
    echo "Note: Dependency installation may take several minutes. Please wait..." >&2
    npm install
fi

# Check if dist directory exists, if not build the project
if [ ! -d "dist" ]; then
    echo "Building project..." >&2
    npm run build
fi

# Environment variables will be loaded from .env file by Node.js

# Start the MCP server
node dist/index.js
